<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const activeIndex = ref('0')
const isEnglish = ref(false)
const languageIndex = ref(1)

const url =
  'https://agc-storage-drcn.platform.dbankcloud.cn/v0/default-bucket-rwdjv/YuaYangIntelligence%2Flogo.jpg?token=172fea34-1a1a-43bb-86c8-46eb76781afb'

const handleSelect = (index: string) => {
  activeIndex.value = index
  const selectedLink = navItems.value.find(item => item.id.toString() === index)
  if (selectedLink) {
    router.push(selectedLink.path)
  }
}



const toggleLanguage = (index: number) => {
    index === 0 ? isEnglish.value = true : isEnglish.value = false
}

// 导航数据
const navItems = ref([
  { name: { zh: '公司介绍', en: 'Company' }, path: '/', id: 0 },
  { name: { zh: '产品展示', en: 'Products' }, path: '/products', id: 1 },
  { name: { zh: '人才招聘', en: 'Careers' }, path: '/careers', id: 2 },
  //  { name: { zh: '关于我们', en: 'About' }, path: '/about', id: 3 }
])
</script>

<template>
  <el-header class="header-container">
    <div class="header-content">
      <!-- 左侧Logo -->
      <div class="logo">
        <el-image 
          style="width: 120px; height: 60px"
          :src="url"
          fit="contain"
        >
          <template #error>
            <div class="logo-placeholder">
              <span>LOGO</span>
            </div>
          </template>
        </el-image>
        <div>
          <h3>圆阳智能</h3>
          <p>roundyoung</p>
        </div>
      </div>

      <!-- 中间导航菜单 -->
      <el-menu
        :default-active="activeIndex"
        mode="horizontal"
        class="nav-menu"
        @select="handleSelect"
      >
        <el-menu-item
          v-for="item in navItems"
          :key="item.id"
          :index="item.id.toString()"
          class="custom-menu-item"
        >
          {{ isEnglish ? item.name.en : item.name.zh }}
        </el-menu-item>
      </el-menu>

      <!-- 右侧语言切换 -->
      <div class="language-switch">
    <span 
      @click="toggleLanguage(0)"
      :class="{ 'active-language': isEnglish }"
    >English</span>
    <span> / </span>
    <span 
      @click="toggleLanguage(1)"
      :class="{ 'active-language': !isEnglish }"
    >中文</span>
  </div>
    </div>
  </el-header>
</template>

<style scoped lang="scss">
.header-container {
  height: 80px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  
  .header-content {
    width: 1200px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}

.logo {
  display: flex;
  align-items: center;
  
  .logo-placeholder {
    width: 120px;
    height: 60px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
  }
}

.nav-menu {
  border-bottom: none;
  flex: 1;
  display: flex;
  justify-content: center;
  
  :deep(.el-menu-item) {
    height: 80px;
    line-height: 80px;
    font-size: 16px;
    color: #333;
    position: relative;
    border-bottom: none !important;
    margin: 0 15px;
    
    &:not(.is-active):hover {
      color: #ff0000 !important;
      background-color: transparent !important;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: 20%;
        height: 2px;
        background: #ff0000;
      }
    }
    
    &.is-active {
      color: #ff0000 !important;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: 20%;
        height: 2px;
        background: #ff0000;
      }
    }
  }
}

.language-switch {
  margin-left: auto;
  > span {
    cursor: pointer;
    transition: color 0.3s ease;
    
    &:hover {
      color: #ff0000;
    }
    
    &.active-language {
      color: #ff0000;
      font-weight: bold;
    }
  }
  
  > span:not(:first-child):not(:last-child) {  /* 中间的斜杠样式 */
    cursor: default;
    &:hover {
      color: inherit;
    }
  }
}

@keyframes underline {
  from {
    width: 0;
  }
  to {
    width: 60%;
  }
}
:deep(.el-menu--horizontal > .el-menu-item) {
  background-color: transparent !important;
}
</style>